package login

import (
	"class2-4/datebase"
	"fmt"
)

type Classmates struct {
	Name string
	Sn   string
	Id   int
	Pswd string
}

func Denglu() {
	fmt.Println("请输入你的学号")
	var sn string
	fmt.Scanln(&sn)
	fmt.Println("请输入你的密码")
	var mima string
	fmt.Scanln(&mima)
	fmt.Println("你的学号和密码分别是：", sn, mima)

	var Dengluyonghu Classmates
	datebase.DB.Raw("select*from classmates.classmates where sn=" + sn).Scan(&Dengluyonghu)
	if Dengluyonghu.Pswd == mima {
		fmt.Println("登录成功", Dengluyonghu.Name)
	} else {
		fmt.Println("登录失败，请检查")
	}
}

func ChaXunsuoyouXuesheng() {
	fmt.Println("下面是所有学生信息：")
	var allStudents []Classmates
	datebase.DB.Raw("select name,id,sn,pswd from classmates.classmates").Scan(&allStudents)
	for _, oneStudengt := range allStudents {
		fmt.Println(oneStudengt.Name, "学号", oneStudengt.Sn, "密码", oneStudengt.Pswd)
	}
}
